﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Xml;

namespace SPWebShell.entity
{
    [DebuggerDisplay("InternalName={InternalName}")]
    public class SPField
    {
        Dictionary<string, string> _namevalues;
        XmlNode _ndData;
        public SPField()
        {
            _namevalues = new Dictionary<string, string>();
        }
        public SPField(XmlNode ndField)
        {
            _ndData = ndField;
            _namevalues = new Dictionary<string, string>();
            foreach (XmlAttribute attr in ndField.Attributes)
            {
                _namevalues.Add(attr.Name, attr.Value);
            }
        }
        public string ID 
        {
            get
            {
                return _namevalues["ID"];
            }
        }
        public string DisplayName
        {
            get
            {
                return _namevalues["DisplayName"];
            }
        }
        public string InternalName
        {
            get
            {
                return _namevalues["StaticName"];
            }
        }
        public bool  ReadOnly
        {
            get
            {
                try
                {
                    return Boolean.Parse(_namevalues["ReadOnly"]);
                }
                catch
                {
                    return false;
                }
            }
        }
        public string Type 
        { 
        get
            {
                return _namevalues["Type"];
            }
        }
        public bool FromBaseType 
            {
                get
                {
                    if (!_namevalues.ContainsKey("FromBaseType")) return false;
                    string frombasetype = _namevalues["FromBaseType"];
                    if (frombasetype == "TRUE")
                        return true;
                    else
                        return false;
                }
            }
    }
}
